
SET(CMAKE_VERBOSE_MAKEFILE ON)

SET(YDRA_CMAKE_HOME /usr/share/cmake/ydra)

# project name
PROJECT( mpl-grammar )

SET( ANTLR_VOCABULARY_NAME Mpl )

SET( LEXER_SOURCE_FILES MplLexer.g )
SET( PARSER_SOURCE_FILES MplParser.g )

MESSAGE ( STATUS "Lexer sources: ${LEXER_SOURCE_FILES}" )
MESSAGE ( STATUS "Grammar sources: ${PARSER_SOURCE_FILES}" )


SET( LEXER_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)

SET( QT_DONT_USE_QTCORE TRUE )
SET( QT_DONT_USE_QTGUI TRUE )
SET( QT_USE_QT3SUPPORT FALSE )
SET( QT_USE_QTASSISTANT FALSE )
SET( QT_USE_QTDESIGNER FALSE )
SET( QT_USE_QTMOTIF FALSE )
SET( QT_USE_QTMAIN FALSE )
SET( QT_USE_QTNETWORK FALSE )
SET( QT_USE_QTNSPLUGIN FALSE )
SET( QT_USE_QTOPENGL FALSE )
SET( QT_USE_QTSQL FALSE )
SET( QT_USE_QTXML TRUE )
SET( QT_USE_QTSVG FALSE )
SET( QT_USE_QTTEST FALSE )
SET( QT_USE_QTUITOOLS FALSE )

find_package(Qt4 REQUIRED) # find and setup Qt3 for this project
add_definitions( ${QT_DEFINITIONS} )
link_directories(${QT_LIBRARY_DIR} ${QT_PLUGINS_DIR})
#FILE(GLOB LEXER_CPP_SOURCES src/*.cpp)

INCLUDE ( ${YDRA_CMAKE_HOME}/antlr_lexer_rules.cmake )
INCLUDE ( ${YDRA_CMAKE_HOME}/antlr_parser_rules.cmake)
INCLUDE ( ${YDRA_CMAKE_HOME}/generated_cpp_sources.cmake )

GENERATE_LEXER_RULES( LEXER_GENERATED_SOURCE LEXER_GENERATED_HEADER LEXER_GENERATED_TOKENS_HEADER LEXER_GENERATED_TOKENS_TXT ${LEXER_SOURCE_FILES} )

GENERATE_PARSER_RULES( PARSER_GENERATED_SOURCE PARSER_GENERATED_HEADER PARSER_GENERATED_TOKENS_HEADER PARSER_GENERATED_TOKENS_TXT ${PARSER_SOURCE_FILES} )

ADD_TO_GENERATED_HEADERS(GENERATED_CPP_HEADERS ${LEXER_GENERATED_HEADER} ${LEXER_GENERATED_TOKENS_HEADER} ${PARSER_GENERATED_HEADER} ${PARSER_GENERATED_TOKENS_HEADER})

ADD_TO_GENERATED_SOURCES(GENERATED_CPP_SOURCES ${LEXER_GENERATED_SOURCE} ${PARSER_GENERATED_SOURCE} )



include_directories (
    ${QT_INCLUDES}
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/include/generated
    /opt/antlr/include)

AUX_SOURCE_DIRECTORY(src ANTLR_SOURCES)

MESSAGE(STATUS "sources: ${ANTLR_SOURCES} ")
add_library ( MplParser SHARED ${GENERATED_CPP_SOURCES} ${ANTLR_SOURCES} )
ADD_DEPENDENCIES( MplParser GENERATED_HEADERS)
ADD_DEPENDENCIES( MplParser GENERATED_SOURCES)

TARGET_LINK_LIBRARIES( MplParser /opt/antlr/lib/libantlr.a )
TARGET_LINK_LIBRARIES( MplParser ${QT_LIBRARIES} )


INSTALL(TARGETS MplParser LIBRARY DESTINATION lib)
